// CEditColor.cpp : Implementierungsdatei
//

#include "stdafx.h"
#include "Charplan.h"
#include "CEditColor.h"
// #include "CEditColor.h" // precompiled header


// CEditColor

IMPLEMENT_DYNAMIC(CEditColor, CEdit)
CEditColor::CEditColor()
{
    mb_islink = false;
    m_bMouseOver = false;

    m_hand_cursor = AfxGetApp()->LoadStandardCursor(MAKEINTRESOURCE(32649));// = IDC_HAND

    SetColorsDefault();
}


void CEditColor::SetTextColor(COLORREF col)
{
    if (m_clrText != col)
    {
        m_clrText = col;
        if (::IsWindow(m_hWnd)) Invalidate();
    }
}

void CEditColor::SetBackground(COLORREF col)
{
    m_clrBkgnd = col;
    m_brBkgnd.DeleteObject();
    m_brBkgnd.CreateSolidBrush(m_clrBkgnd);
}


void CEditColor::SetColorsDefault()
{
    SetTextColor(GetSysColor(COLOR_WINDOWTEXT));

    if (IsWindow(m_hWnd) && (GetStyle() & ES_READONLY))
        SetBackground(GetSysColor(COLOR_BTNFACE));
    else
        SetBackground(GetSysColor(COLOR_WINDOW));
}


CEditColor::~CEditColor()
{
}



BEGIN_MESSAGE_MAP(CEditColor, CEdit)
    ON_WM_CTLCOLOR_REFLECT()
    ON_WM_SETCURSOR()
    ON_WM_LBUTTONUP()
END_MESSAGE_MAP()



// CEditColor-Meldungshandler


HBRUSH CEditColor::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
{
    pDC->SetTextColor(m_clrText);     // text
    pDC->SetBkColor(m_clrBkgnd);     // text bkgnd
    return m_brBkgnd;            // ctl bkgnd
}

void CEditColor::SetBold(bool enable /*=true*/)
{
    LOGFONT logf;
    GetFont()->GetLogFont(&logf);

    logf.lfWeight = enable?FW_MEDIUM:FW_NORMAL;

    m_font.DeleteObject();
    m_font.CreateFontIndirect(&logf);
    SetFont(&m_font);
}


void CEditColor::SetIsALink(bool bl /*= true*/)
{
    mb_islink = bl;

    LOGFONT logf;
    GetFont()->GetLogFont(&logf);

    logf.lfUnderline = bl;

    m_font.DeleteObject();
    m_font.CreateFontIndirect(&logf);
    SetFont(&m_font);

}


BOOL CEditColor::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
    if (mb_islink && m_hand_cursor)
    {
        // on Win95 is no hand
        SetCursor(m_hand_cursor);
        return TRUE;
    }

    return CEdit::OnSetCursor(pWnd, nHitTest, message);
}



void CEditColor::SetLink(const CString& str)
{
    m_link = str;
    SetIsALink(!m_link.IsEmpty());
}



void CEditColor::OnLButtonUp(UINT nFlags, CPoint point)
{
    if (m_link && mb_islink)
    {
        ShellExecute(NULL,_T("open"),m_link,NULL,NULL,SW_SHOW);
    }

    CEdit::OnLButtonUp(nFlags, point);
}
